<?php
/**
 * @license http://www.gnu.org/licenses/lgpl.html LGPL
 * @author Harlan Iverson <h dot iverson at gmail dot com>
 * @copyright Copyright (c) 2006, Harlan Iverson.
 * @version $Id: test-faces-config.php 20 2006-08-01 05:54:40Z Harlan $
 */
 
 
 

require_once 'HTML/Template/Smarty/Smarty.class.php';
require_once '../public-site/classes/ViewHandler.class.php';
require_once '../public-site/classes/FacesContext.class.php';
require_once 'PHPUnit.php';

class FacesConfigTest extends PHPUnit_TestCase {

	var $facesConfig;

	function __construct($name) {
		$this->PHPUnit_TestCase($name);
	}
	
	function setUp() {
		$this->facesConfig =& new FacesConfig( "faces-config.xml" );
		$this->facesConfig->parse();
	}
	

	
	function testResolveBean() {
	}
	
	function testResolveFieldProperty() {
		$value = $this->facesContext->resolve( "#{testBean.fieldProperty}" );
		
		$testBean = new TestBean();
		
		$this->assertEquals( $testBean->fieldProperty, $value );
	}
	
	function testResolveAccessorProperty() {
		$value = $this->facesContext->resolve( "#{testBean.accessorProperty}" );
		
		$testBean = new TestBean();
		
		$this->assertEquals( $testBean->getAccessorProperty(), $value );
	}
	
	function testResolveNestedFieldProperty() {
		$value = $this->facesContext->resolve( "#{testBean.nestedClassProperty.fieldProperty}" );
		
		$testBean = new TestBean();
		
		$this->assertEquals( $testBean->nestedClassProperty->fieldProperty, $value );
	}
	
	function testResolveAction() {
		$value = $this->facesContext->resolve( "#{testBean.doSomeAction}" );

		$testBean = new TestBean();

		$this->assertTrue( is_callable( $value ) );
		
		$this->assertEquals( $testBean->doSomeAction(), call_user_func($value) );
	}
	
	function testResolveString() {
		try {
			$valueToResolve = "stuff is neat";
			$value = $this->facesContext->resolve( $valueToResolve );
			$this->assertEquals( $valueToResolve, $value );
		}catch( Exception $e ) {
			$this->fail( "did not resolve plain string." );
		}
	}
	
	function testResolveGarbage() {
		try {
			$value = $this->facesContext->resolve( "#{testBean.fsdfs}" );
			$this->fail( "resolved garbage" );
		}catch( Exception $e ) {
			// pass
		}
	}
	
	
	function testGetRequestName() {
		$name = $this->facesContext->getRequestName( "#{someBean.someProperty}" );
		$this->assertEquals( "faces-someBean__someProperty", $name );
		
		$name = $this->facesContext->getRequestName( "#{someBean.nestedClass.someProperty}" );
		$this->assertEquals( "faces-someBean__nestedClass__someProperty", $name );
	}
	
	function testGetActionName() {
		$name = $this->facesContext->getActionName( "#{someBean.someAction}" );
		$this->assertEquals( "action-someBean__someAction", $name );
		
		$name = $this->facesContext->getActionName( "#{someBean.nestedClass.someAction}" );
		$this->assertEquals( "action-someBean__nestedClass__someAction", $name );
	}
	
	function zz_testNavigationRules() {
		$this->facesContext->registerNavigationRules( 
			$handlers = array(
				new OutcomeMapping( null, "requestQuoteBean.requestQuote", "success", "request-quote-success" ),
				new OutcomeMapping( null, "requestQuoteBean.requestQuote", "failure", "request-quote-failure" ),
				new OutcomeMapping( null, "realtimeQuoteBean.quickQuote", "success", "realtime-quote-success" ),
				new OutcomeMapping( null, "realtimeQuoteBean.quickQuote", "no-coverage", "request-quote-failure" ),
				new OutcomeMapping( null, "loginBean.logout", null, "logged-out" ),
				new OutcomeMapping( null, "loginBean.login", "logged-in", "our-company" ),
			
				new OutcomeMapping( null, "quickCallBackFormBean.submit", "success", "quick-callback-success" )
			)
		);
		
		
	}
	

}



?>